package com.effectiv.req1.email;

import java.util.Locale;

import jodd.util.StringUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

@AllArgsConstructor
@Slf4j
public class EmailBodyPreparer<T> {
	
	
	private T entity;
	private String templateName;
	private Locale locale;
	
	
	
	public String prepareFromTemplate(TemplateEngine templateEngine){
		final Context context = new Context(locale);
		context.setVariable(StringUtil.decapitalize(entity.getClass().getSimpleName()), entity);
		
		String html = templateEngine.process(templateName, context);
		
		
		log.info("HTML == {}", html);
		
		return html;
	}
}

